% Author: Vasyl Mykhalchuk
% Created: 30/01/2012

classdef AnimatedMesh < handle
    properties 
        mRefMesh
        mAM = 0;
        mNumberFrames = 0;
        mAdjList % adjacent faces
        mAdjVertList % adjacent vertices
    end % properties
    
    methods
        
        % Constructor
        function obj = AnimatedMesh(name, fileName)
            obj.mAM = load( fileName );
            obj.mRefMesh = Mesh(obj.mAM.frames(1, :), obj.mAM.topology);
            [obj.mNumberFrames] = size(obj.mAM.frames, 1);            
            
            % Create adjacency lists
            addpath(genpath('..'));
            try
                adj = load([name 'Adj.mat']);
                obj.mAdjList = adj.adjList;
                obj.mAdjVertList = adj.adjVertList;
            catch err
                adjList = createAdjacencyList(obj.mRefMesh.mFaces, obj.mRefMesh.mNumberV, obj.mRefMesh.mNumberF);
                adjVertList = createVertexAdjacencyList(obj.mRefMesh.mFaces, obj.mRefMesh.mNumberV, obj.mRefMesh.mNumberF);
                obj.mAdjList = adjList;
                obj.mAdjVertList = adjVertList;
                save([name 'Adj.mat'], 'adjList', 'adjVertList');
            end
        end % Constructor
    
        function [mesh] = getMeshForFrame(obj, frameId)
            mesh = Mesh(obj.mAM.frames(frameId, :), obj.mAM.topology);
        end % function getMeshForFrame
        function [] = ccw(vert_list, index)
        end % function ccw
        function [] = ccwOrder(obj)
            mesh = obj.getMeshForFrame(1);
            nV = mesh.mNumberV;
            for i = 1 : nV
            end % for
        end % function ccwOrder
        
    end % methods
    
end % classdef AnimatedMesh

